﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Model;
using BLL;
using Common;

public partial class Manager_UserMessager : BasePage
{
    UserBLL bll = new UserBLL();
    User user = new User();
    protected static string Content;
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        TestPurview(HttpContext.Current, 1);
        if (!IsPostBack)
        {
            this.PageOn1.pageSize = 10;
            this.PageOn1.total = bll.getSqlRecodeCount();

            GetBind();
        }
    }

    private void GetBind() {
        DataTable dt = bll.GetList(10,this.PageOn1.currentPage);

        if (dt.Rows.Count>0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int num = i + 1;
                sb.Append("<tr>");
                sb.Append("<td>" + num + "</td>");
                sb.AppendFormat("<td><input type=\"checkbox\" name=\"box\" value='" + dt.Rows[i]["uid"].ToString() + "'onclick=\"checkbox()\"/></td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["userName"].ToString() + "</td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["company"].ToString() + "</td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["linkman"].ToString() + "</td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["qq"].ToString() + "</td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["email"].ToString() + "</td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["tel"].ToString() + "</td>");
                sb.AppendFormat("<td>" + dt.Rows[i]["fax"].ToString() + "</td>");
                if (dt.Rows[i]["state"].ToString()=="0")
                {
                    sb.AppendFormat("<td>正常使用</td>");
                }
                else if (dt.Rows[i]["state"].ToString()=="1")
                {
                    sb.AppendFormat("<td>停止使用</td>");
                }

                if (dt.Rows[i]["type"].ToString()=="0")
                {
                    sb.AppendFormat("<td>超级用户</td>");
                }
                else if (dt.Rows[i]["type"].ToString()=="1")
                {
                    sb.AppendFormat("<td>管理员</td>");
                }
                else if (dt.Rows[i]["type"].ToString()=="2")
                {
                    sb.AppendFormat("<td>原料供应商</td>");
                }
                else if (dt.Rows[i]["type"].ToString()=="3")
                {
                    sb.AppendFormat("<td>客户</td>");
                }
                else if (dt.Rows[i]["type"].ToString()=="4")
                {
                    sb.AppendFormat("<td>外协</td>");
                }
                
                sb.AppendFormat("<td>" + dt.Rows[i]["comment"].ToString() + "</td>");
                sb.AppendFormat("<td><p><span>" + dt.Rows[i]["briefIntro"].ToString() + "</span></p></td>");
            }
            Content = sb.ToString();
        }
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (this.txtId.Text != "")
        {
            string[] uidStr = this.txtId.Text.Split(',');
            for (int i = 0; i < uidStr.Length-1; i++)
            {
                if (bll.Delete(Convert.ToInt32(uidStr[i])))
                {

                }
                else
                {

                }
            }
            Response.Redirect("UserMessager.aspx");
        }
        else
        {
            Response.Write("<script>alert('请选择您要删除的用户信息！')</script>");
            Response.Redirect("UserMessager.aspx");
        }
    }

    protected void PageOn1_PageChanged(object sender, EventArgs e)
    {
        GetBind();
    }
}
